package com.hotel.servlet; /**
 * @author KungSu.
 * @create 2021-05-14 6:58
 */

import com.hotel.bean.Account;
import com.hotel.bean.Order;
import com.hotel.bean.OrderWithHotelName;
import com.hotel.dao.OrderDao;
import com.hotel.util.DBOperation;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "DingdanInfoServlet", value = "/DingdanInfoServlet")
public class DingdanInfoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Account account = (Account) request.getSession().getAttribute("curUser");
        SqlSession sqlSession = DBOperation.getSqlSession();
        OrderDao orderDao = sqlSession.getMapper(OrderDao.class);
        System.out.println(account.getAccount_id());
        List<OrderWithHotelName> orders = orderDao.findOrderAndHotelName(account.getAccount_id());
//        DateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        for (Order order: orders){
            System.out.println(order);
        }

        sqlSession.close();
        request.setAttribute("order",orders);
        request.getRequestDispatcher("/jsp/wodedingdanxinxi.jsp").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
